﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:Beetle.Sl.EditorControl" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:converters="clr-namespace:Beetle.Sl.EditorControl.Converters"
    xmlns:localcontrols="clr-namespace:Beetle.Sl.EditorControl.Controls">

    <converters:BooleanToGrayEffectConverter x:Key="booleanToGrayEffectConverter"/>
    <converters:BooleanToOpacityConverter x:Key="booleanToOpacityConverter"/>
    <converters:BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>
    <converters:ToolBarItemVisualTypeToVisibilityConverter x:Key="toolBarItemVisualTypeToVisibilityConverter" />

    <ControlTemplate x:Key="ValidationToolTipTemplate">
        <Grid x:Name="Root" Margin="5,0" RenderTransformOrigin="0,0" Opacity="0">
            <Grid.RenderTransform>
                <TranslateTransform x:Name="xform" X="-25"/>
            </Grid.RenderTransform>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup Name="OpenStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition GeneratedDuration="0"/>
                        <VisualTransition To="Open" GeneratedDuration="0:0:0.2">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0" Duration="0:0:0.2">
                                    <DoubleAnimation.EasingFunction>
                                        <BackEase Amplitude=".3" EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2"/>
                            </Storyboard>
                        </VisualTransition>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Closed">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Open">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0" Duration="0"/>
                            <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

            <Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5"/>
            <Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4"/>
            <Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3"/>
            <Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2"/>

            <Border Background="#FFDC000C" CornerRadius="2"/>
            <Border CornerRadius="2">
                <TextBlock 
                  UseLayoutRounding="false" 
                  Foreground="White" Margin="8,4,8,4" MaxWidth="250" TextWrapping="Wrap" Text="{Binding (Validation.Errors)[0].ErrorContent}"/>
            </Border>
        </Grid>
    </ControlTemplate>

    <Style TargetType="TextBox">
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Background" Value="#FFFFFFFF"/>
        <Setter Property="Foreground" Value="#FF000000"/>
        <Setter Property="Padding" Value="2"/>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <Grid x:Name="RootElement">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" To="#FF99C1E2" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="ReadOnly">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ReadOnlyVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="0" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid"/>
                                <VisualState x:Name="InvalidUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="InvalidFocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsOpen">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1" Opacity="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
                            <Grid>
                                <Border x:Name="ReadOnlyVisualElement" Opacity="0" Background="#5EC9C9C9"/>
                                <Border x:Name="MouseOverBorder" BorderThickness="1" BorderBrush="Transparent">
                                    <ScrollViewer x:Name="ContentElement" Padding="{TemplateBinding Padding}" BorderThickness="0" IsTabStop="False"/>
                                </Border>
                            </Grid>
                        </Border>
                        <Border x:Name="DisabledVisualElement" Background="#A5F7F7F7" BorderBrush="#A5F7F7F7" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0" IsHitTestVisible="False"/>
                        <Border x:Name="FocusVisualElement" BorderBrush="#FF6DBDD1" BorderThickness="{TemplateBinding BorderThickness}" Margin="1" Opacity="0" IsHitTestVisible="False"/>
                        <Border x:Name="ValidationErrorElement" BorderThickness="1" CornerRadius="1" BorderBrush="#FFDB000C" Visibility="Collapsed">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Name="validationTooltip" Template="{StaticResource ValidationToolTipTemplate}" Placement="Right" 
                         PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                         DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                                    <ToolTip.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <EventTrigger.Actions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsHitTestVisible">
                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <sys:Boolean>true</sys:Boolean>
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger.Actions>
                                        </EventTrigger>
                                    </ToolTip.Triggers>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Grid Width="12" Height="12" HorizontalAlignment="Right" Margin="1,-4,-4,0" VerticalAlignment="Top" Background="Transparent">
                                <Path Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C"/>
                                <Path Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff"/>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>




    <Style x:Key="EditorRichTextBox" TargetType="RichTextBox">
        <Setter Property="BorderThickness" Value="1" />
        <!--<Setter Property="Background" Value="#FFFFFFFF" />-->
        <Setter Property="Foreground" Value="#FF000000" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="BorderBrush" Value="#00000000" />
        <!--<Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RichTextBox">
                    <Grid x:Name="RootElement">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" To="#FF99C1E2" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="ReadOnly" >
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="0" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid"/>
                                <VisualState x:Name="InvalidUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="InvalidFocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsOpen">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1" Opacity="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
                            <Border x:Name="MouseOverBorder" BorderThickness="1" BorderBrush="Transparent">
                                <ScrollViewer x:Name="ContentElement" Padding="{TemplateBinding Padding}" BorderThickness="0" IsTabStop="False" />
                            </Border>
                        </Border>
                        <Border x:Name="DisabledVisualElement" Background="#A5F7F7F7" BorderBrush="#A5F7F7F7" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0" IsHitTestVisible="False"/>
                        <Border x:Name="FocusVisualElement"  BorderBrush="#FF6DBDD1" BorderThickness="{TemplateBinding BorderThickness}" Margin="1" Opacity="0" IsHitTestVisible="False"/>
                        <Border x:Name="ValidationErrorElement" BorderThickness="1" CornerRadius="1" BorderBrush="#FFDB000C" Visibility="Collapsed">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Name="validationTooltip" Template="{StaticResource ValidationToolTipTemplate}" Placement="Right" 
                         PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                         DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                                    <ToolTip.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <EventTrigger.Actions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsHitTestVisible">
                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <sys:Boolean>true</sys:Boolean>
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger.Actions>
                                        </EventTrigger>
                                    </ToolTip.Triggers>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Grid Width="12" Height="12" HorizontalAlignment="Right" Margin="1,-4,-4,0" VerticalAlignment="Top" Background="Transparent">
                                <Path Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C"/>
                                <Path Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff"/>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



    <!-- Editor -->
    <Style TargetType="local:Editor">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid x:Name="Root" Background="{TemplateBinding Background}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="ValidationStates">
                                    <VisualState x:Name="Valid"/>
                                    <VisualState x:Name="InvalidUnfocused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="InvalidFocused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsOpen">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>-->
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border Grid.Row="0" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ToolBarVisibility}">
                                <ListBox  Margin="0" Padding="0" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ToolBarGroups}">
                                    <ListBox.Template>
                                        <ControlTemplate>
                                            <ItemsPresenter/>
                                        </ControlTemplate>
                                    </ListBox.Template>
                                    <ListBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal">
                                            </StackPanel>
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>
                                    <ListBox.ItemContainerStyle>
                                        <Style TargetType="ListBoxItem">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate>
                                                        <ContentPresenter/>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </ListBox.ItemContainerStyle>
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Border Margin="1" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3" HorizontalAlignment="Left" Background="#64FFFFFF">
                                                <Border Margin="1,1,6,1" Padding="0,0,6,0" CornerRadius="2" Background="#1A000000">
                                                    <Grid>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition  Width="Auto"/>
                                                            <ColumnDefinition Width="*" />
                                                        </Grid.ColumnDefinitions>
                                                        <StackPanel Grid.Column="0" VerticalAlignment="Center" Margin="2,0">
                                                            <Rectangle Margin="1" Fill="#55000000" Width="2" Height="2"/>
                                                            <Rectangle Margin="1" Fill="#55000000" Width="2" Height="2"/>
                                                            <Rectangle Margin="1" Fill="#55000000" Width="2" Height="2"/>
                                                            <Rectangle Margin="1" Fill="#55000000" Width="2" Height="2"/>
                                                        </StackPanel>
                                                        <Border Grid.Column="1">
                                                            <ListBox Margin="0" Padding="0" ItemsSource="{Binding Items}">
                                                                <ListBox.Template>
                                                                    <ControlTemplate>
                                                                        <ItemsPresenter/>
                                                                    </ControlTemplate>
                                                                </ListBox.Template>
                                                                <ListBox.ItemsPanel>
                                                                    <ItemsPanelTemplate>
                                                                        <StackPanel Orientation="Horizontal">
                                                                        </StackPanel>
                                                                    </ItemsPanelTemplate>
                                                                </ListBox.ItemsPanel>
                                                                <ListBox.ItemContainerStyle>
                                                                    <Style TargetType="ListBoxItem">
                                                                        <Setter Property="Template">
                                                                            <Setter.Value>
                                                                                <ControlTemplate>
                                                                                    <ContentPresenter/>
                                                                                </ControlTemplate>
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                    </Style>
                                                                </ListBox.ItemContainerStyle>
                                                                <ListBox.ItemTemplate>
                                                                    <DataTemplate>
                                                                        <Grid Height="22" Effect="{Binding IsEnabled, Converter={StaticResource booleanToGrayEffectConverter}}"  Opacity="{Binding IsEnabled, Converter={StaticResource booleanToOpacityConverter},ConverterParameter=1-0.4}">
                                                                            <i:Interaction.Triggers>
                                                                                <i:EventTrigger EventName="MouseEnter">
                                                                                    <ei:ControlStoryboardAction>
                                                                                        <ei:ControlStoryboardAction.Storyboard>
                                                                                            <Storyboard>
                                                                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElementPopup" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                                                        <DiscreteObjectKeyFrame.Value>
                                                                                                            <Visibility>Visible</Visibility>
                                                                                                        </DiscreteObjectKeyFrame.Value>
                                                                                                    </DiscreteObjectKeyFrame>
                                                                                                </ObjectAnimationUsingKeyFrames>
                                                                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                                                        <DiscreteObjectKeyFrame.Value>
                                                                                                            <Visibility>Visible</Visibility>
                                                                                                        </DiscreteObjectKeyFrame.Value>
                                                                                                    </DiscreteObjectKeyFrame>
                                                                                                </ObjectAnimationUsingKeyFrames>
                                                                                            </Storyboard>
                                                                                        </ei:ControlStoryboardAction.Storyboard>
                                                                                    </ei:ControlStoryboardAction>
                                                                                </i:EventTrigger>
                                                                                <i:EventTrigger EventName="MouseLeave">
                                                                                    <ei:ControlStoryboardAction>
                                                                                        <ei:ControlStoryboardAction.Storyboard>
                                                                                            <Storyboard>
                                                                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElementPopup" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                                                        <DiscreteObjectKeyFrame.Value>
                                                                                                            <Visibility>Collapsed</Visibility>
                                                                                                        </DiscreteObjectKeyFrame.Value>
                                                                                                    </DiscreteObjectKeyFrame>
                                                                                                </ObjectAnimationUsingKeyFrames>
                                                                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                                                        <DiscreteObjectKeyFrame.Value>
                                                                                                            <Visibility>Collapsed</Visibility>
                                                                                                        </DiscreteObjectKeyFrame.Value>
                                                                                                    </DiscreteObjectKeyFrame>
                                                                                                </ObjectAnimationUsingKeyFrames>
                                                                                            </Storyboard>
                                                                                        </ei:ControlStoryboardAction.Storyboard>
                                                                                    </ei:ControlStoryboardAction>
                                                                                </i:EventTrigger>
                                                                            </i:Interaction.Triggers>
                                                                            <Grid.ColumnDefinitions>
                                                                                <ColumnDefinition MinWidth="22" Width="Auto"/>
                                                                                <ColumnDefinition Width="Auto"/>
                                                                            </Grid.ColumnDefinitions>
                                                                            <Border x:Name="SelectElement"  Visibility="{Binding IsSelected, Converter={StaticResource booleanToVisibilityConverter}}" Grid.ColumnSpan="2" Background="#FFFFECB5" BorderThickness="1" BorderBrush="#FFE5C365" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                                                                            <Border x:Name="MouseOverElement" Grid.ColumnSpan="2" BorderThickness="1" Opacity="{Binding IsEnabled, Converter={StaticResource booleanToOpacityConverter},ConverterParameter=1-0}" Visibility="Collapsed" BorderBrush="#FFE5C365" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                                                                <Border.Background>
                                                                                    <LinearGradientBrush>
                                                                                        <GradientStop Offset="0" Color="#FFFFFBEF"/>
                                                                                        <GradientStop Offset="1" Color="#FFFFECB5"/>
                                                                                    </LinearGradientBrush>
                                                                                </Border.Background>
                                                                            </Border>
                                                                            <Grid Grid.Column="0">
                                                                                <Button Command="{Binding Command}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Content="{Binding Content}" IsHitTestVisible="True">
                                                                                    <Button.Template>
                                                                                        <ControlTemplate>
                                                                                            <ContentPresenter/>
                                                                                        </ControlTemplate>
                                                                                    </Button.Template>
                                                                                </Button>
                                                                            </Grid>
                                                                            <Grid Grid.Column="1" Width="12" Visibility="{Binding Path=ToolBarItemVisualType, Converter={StaticResource toolBarItemVisualTypeToVisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Stretch">
                                                                                <Border x:Name="MouseOverElementPopup" Opacity="{Binding IsEnabled, Converter={StaticResource booleanToOpacityConverter}, ConverterParameter=1-0}" VerticalAlignment="Stretch" Visibility="Collapsed" HorizontalAlignment="Left" BorderBrush="#FFE5C365" BorderThickness="1,0,0,0"></Border>
                                                                                <Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Command="{Binding PopupCommand}">
                                                                                    <Button.Template>
                                                                                        <ControlTemplate>
                                                                                            <Grid Background="#01FFFFFF" Margin="1">
                                                                                                <ContentPresenter/>
                                                                                            </Grid>
                                                                                        </ControlTemplate>
                                                                                    </Button.Template>
                                                                                    <Button.Content>
                                                                                        <Path Data="M87.16613,115.50053 L95.166771,115.47983 L91.166283,120.42372 z" Fill="#FF293955" HorizontalAlignment="Center" Height="3" Margin="0" Stretch="Fill" Stroke="#FF293955" UseLayoutRounding="False" VerticalAlignment="Center" Width="5"/>
                                                                                    </Button.Content>
                                                                                </Button>
                                                                            </Grid>
                                                                            <Popup IsOpen="{Binding IsOpenPopup}" x:Name="popup">
                                                                                <Popup.RenderTransform>
                                                                                    <TranslateTransform x:Name="yform"></TranslateTransform>
                                                                                </Popup.RenderTransform>
                                                                                <i:Interaction.Triggers>
                                                                                    <i:EventTrigger EventName="Opened">
                                                                                        <ei:ControlStoryboardAction>
                                                                                            <ei:ControlStoryboardAction.Storyboard>
                                                                                                <Storyboard>
                                                                                                    <DoubleAnimationUsingKeyFrames  Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="popupRoot">
                                                                                                        <EasingDoubleKeyFrame KeyTime="0" Value="0"></EasingDoubleKeyFrame>
                                                                                                        <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1"></EasingDoubleKeyFrame>
                                                                                                    </DoubleAnimationUsingKeyFrames>
                                                                                                    <DoubleAnimationUsingKeyFrames  Storyboard.TargetProperty="Y" Storyboard.TargetName="yform">
                                                                                                        <EasingDoubleKeyFrame KeyTime="0" Value="0"></EasingDoubleKeyFrame>
                                                                                                        <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="21"></EasingDoubleKeyFrame>
                                                                                                    </DoubleAnimationUsingKeyFrames>
                                                                                                </Storyboard>
                                                                                            </ei:ControlStoryboardAction.Storyboard>
                                                                                        </ei:ControlStoryboardAction>
                                                                                    </i:EventTrigger>
                                                                                    <i:EventTrigger EventName="Closed">
                                                                                        <ei:ControlStoryboardAction>
                                                                                            <ei:ControlStoryboardAction.Storyboard>
                                                                                                <Storyboard>
                                                                                                    <DoubleAnimationUsingKeyFrames  Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="popupRoot">
                                                                                                        <EasingDoubleKeyFrame KeyTime="0" Value="0"></EasingDoubleKeyFrame>
                                                                                                    </DoubleAnimationUsingKeyFrames>
                                                                                                </Storyboard>
                                                                                            </ei:ControlStoryboardAction.Storyboard>
                                                                                        </ei:ControlStoryboardAction>
                                                                                    </i:EventTrigger>
                                                                                </i:Interaction.Triggers>
                                                                                <Grid x:Name="popupRoot" Opacity="0">
                                                                                    <Border Background="White">
                                                                                        <Border.Effect>
                                                                                            <DropShadowEffect  Color="Black" Opacity="0.3"/>
                                                                                        </Border.Effect>
                                                                                    </Border>
                                                                                    <Border MinHeight="30" MinWidth="40" Child="{Binding PopupContent}" BorderThickness="1" BorderBrush="#FFE5C365"/>
                                                                                </Grid>
                                                                            </Popup>
                                                                        </Grid>
                                                                    </DataTemplate>
                                                                </ListBox.ItemTemplate>
                                                            </ListBox>
                                                        </Border>
                                                    </Grid>
                                                </Border>
                                            </Border>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Border>
                            <Border Grid.Row="1">
                                <RichTextBox x:Name="RichTextBoxInst" Style="{StaticResource EditorRichTextBox}" Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RichTextBoxBackground}"></RichTextBox>
                            </Border>
                            <Border  Grid.Row="1" x:Name="ValidationErrorElement" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="1" CornerRadius="1" BorderBrush="#FFDB000C" Visibility="Collapsed" />
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Button" x:Key="PopupPanelButtonStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Normal"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentPresenter/>
                        <Border Visibility="{Binding Visibility}" BorderBrush="#FFF29436" Width="12" Height="12" BorderThickness="1" >
                            <Border BorderBrush="#FFFFFF" BorderThickness="1">
                            </Border>
                        </Border>
                        <Border x:Name="MouseOverElement" Visibility="Collapsed" BorderBrush="#FFF29436" Width="12" Height="12" BorderThickness="1" >
                            <Border BorderBrush="#FFFFFF" BorderThickness="1">
                            </Border>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="ListBox" x:Key="PopupPanelListBoxStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <ItemsPresenter/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <ContentPresenter/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="localcontrols:ColorSelectPanel">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid x:Name="Root" Background="{TemplateBinding Background}">
                        <Grid Margin="5">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Border x:Name="colorPickerProxy" Visibility="Collapsed" IsHitTestVisible="True" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"></Border>
                            <Grid Grid.Row="0">
                                <ListBox Style="{StaticResource PopupPanelListBoxStyle}" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ThemeColors}">
                                    <ListBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition />
                                                    <RowDefinition />
                                                </Grid.RowDefinitions>
                                                <Grid Grid.Row="0" Margin="2,2,2,6" Background="White">
                                                    <Border  BorderBrush="#FFE2E4E7" BorderThickness="1">
                                                        <Button Style="{StaticResource PopupPanelButtonStyle}" Command="{Binding ElementName=colorPickerProxy, Path=DataContext.SelectColorCommand}" CommandParameter="{Binding}">
                                                            <Button.Content>
                                                                <Border Width="12" Height="12" Background="{Binding ColorString}"></Border>
                                                            </Button.Content>
                                                        </Button>
                                                    </Border>
                                                </Grid>
                                                <Grid Grid.Row="1">
                                                    <Border  BorderBrush="#FFE2E4E7" BorderThickness="1" HorizontalAlignment="Center">
                                                        <ListBox  Style="{StaticResource PopupPanelListBoxStyle}"  ItemsSource="{Binding SubColors}">
                                                            <ListBox.ItemTemplate>
                                                                <DataTemplate>
                                                                    <Grid>
                                                                        <Button Style="{StaticResource PopupPanelButtonStyle}"  Command="{Binding ElementName=colorPickerProxy, Path=DataContext.SelectColorCommand}" CommandParameter="{Binding}">
                                                                            <Button.Content>
                                                                                <Border Width="12" Height="12" Background="{Binding ColorString}"></Border>
                                                                            </Button.Content>
                                                                        </Button>
                                                                    </Grid>
                                                                </DataTemplate>
                                                            </ListBox.ItemTemplate>
                                                        </ListBox>
                                                    </Border>
                                                </Grid>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Grid>
                            <Grid Grid.Row="1" Margin="0,4,0,0">
                                <ListBox Style="{StaticResource PopupPanelListBoxStyle}" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=StandardColors}">
                                    <ListBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="2">
                                                <Border BorderBrush="#FFE2E4E7" BorderThickness="1">
                                                    <Button Style="{StaticResource PopupPanelButtonStyle}" Command="{Binding ElementName=colorPickerProxy, Path=DataContext.SelectColorCommand}" CommandParameter="{Binding}">
                                                        <Button.Content>
                                                            <Border Width="12" Height="12" Background="{Binding ColorString}"></Border>
                                                        </Button.Content>
                                                    </Button>
                                                </Border>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Grid>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="localcontrols:FontSizeSelectPanel">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid x:Name="Root" Background="{TemplateBinding Background}">
                        <Border x:Name="sizePickerProxy" Visibility="Collapsed" IsHitTestVisible="True" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"></Border>
                        <ListBox ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path= FontSizeLib}" BorderThickness="0">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <ContentPresenter />
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Button Command="{Binding  ElementName=sizePickerProxy, Path=DataContext.SelectSizeCommand}" CommandParameter="{Binding}">
                                            <Button.Template>
                                                <ControlTemplate>
                                                    <Grid>
                                                        <VisualStateManager.VisualStateGroups>
                                                            <VisualStateGroup x:Name="CommonStates">
                                                                <VisualState x:Name="MouseOver">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                                <DiscreteObjectKeyFrame.Value>
                                                                                    <Visibility>Visible</Visibility>
                                                                                </DiscreteObjectKeyFrame.Value>
                                                                            </DiscreteObjectKeyFrame>
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="Normal"/>
                                                            </VisualStateGroup>
                                                        </VisualStateManager.VisualStateGroups>
                                                        <ContentPresenter/>
                                                        <Border Visibility="{Binding Visibility}" BorderBrush="#FFF29436" BorderThickness="1" >
                                                            <Border BorderBrush="#FFFFFF" BorderThickness="1">
                                                            </Border>
                                                        </Border>
                                                        <Border x:Name="MouseOverElement" Visibility="Collapsed" BorderBrush="#FFF29436" BorderThickness="1" >
                                                            <Border BorderBrush="#FFFFFF" BorderThickness="1">
                                                            </Border>
                                                        </Border>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Button.Template>
                                            <Button.Content>
                                                <TextBlock Margin="5" Text="{Binding Size}" FontSize="{Binding Size}"></TextBlock>
                                            </Button.Content>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- FontFamilySelectPanel -->
    <Style TargetType="localcontrols:FontFamilySelectPanel">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid x:Name="Root" Background="{TemplateBinding Background}">
                        <Border x:Name="fontFamilySelectPanelProxy" Visibility="Collapsed" IsHitTestVisible="True" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"></Border>
                        <ListBox ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontFamilyNames}" BorderThickness="0">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <ContentPresenter />
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Button Command="{Binding  ElementName=fontFamilySelectPanelProxy, Path=DataContext.SelectFontFamilyNameCommand}" CommandParameter="{Binding}">
                                            <Button.Template>
                                                <ControlTemplate>
                                                    <Grid>
                                                        <VisualStateManager.VisualStateGroups>
                                                            <VisualStateGroup x:Name="CommonStates">
                                                                <VisualState x:Name="MouseOver">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                                <DiscreteObjectKeyFrame.Value>
                                                                                    <Visibility>Visible</Visibility>
                                                                                </DiscreteObjectKeyFrame.Value>
                                                                            </DiscreteObjectKeyFrame>
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="Normal"/>
                                                            </VisualStateGroup>
                                                        </VisualStateManager.VisualStateGroups>
                                                        <ContentPresenter/>
                                                        <Border Visibility="{Binding Visibility}" BorderBrush="#FFF29436" BorderThickness="1" >
                                                            <Border BorderBrush="#FFFFFF" BorderThickness="1">
                                                            </Border>
                                                        </Border>
                                                        <Border x:Name="MouseOverElement" Visibility="Collapsed" BorderBrush="#FFF29436" BorderThickness="1" >
                                                            <Border BorderBrush="#FFFFFF" BorderThickness="1">
                                                            </Border>
                                                        </Border>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Button.Template>
                                            <Button.Content>
                                                <TextBlock Margin="5" Text="{Binding Description}" FontSize="12" FontFamily="{Binding Name}"></TextBlock>
                                            </Button.Content>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
